using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;

namespace BriansClimb.GameObjects
{
    /// <summary>
    /// This is the Game Componenet that Manages the In-Game Music and Sound Effects.
    /// </summary>
    public class AudioManager : Microsoft.Xna.Framework.GameComponent
    {
        protected Game game;
        private AudioEngine audioEngine;
        private WaveBank waveBank;
        private SoundBank soundBank;

        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="game">Main Game Object</param>
        public AudioManager(Game game)
            : base(game)
        {
            this.game = game;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {   
            audioEngine = new AudioEngine("Content\\Audio\\BCsound.xgs");
            soundBank = new SoundBank(audioEngine, "Content\\Audio\\Sound Bank.xsb");
            waveBank = new WaveBank(audioEngine, "Content\\Audio\\Wave Bank.xwb");


            base.Initialize();

        }

        /// <summary>
        /// Plays the selected .wav file
        /// </summary>
        /// <param name="cue">Name of the sound file</param>
        public void PlayCue(string cue)
        {
            soundBank.PlayCue(cue);
        }

        /// <summary>
        /// Returns the selected .wav file
        /// </summary>
        /// <param name="cue">Name of the sound file</param>
        /// <returns>the sound file</returns>
        public Cue GetCue(string cue)
        {
            return soundBank.GetCue(cue);
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            //allows the audio component to process the sounds
            audioEngine.Update();

            base.Update(gameTime);
        }
    }
}